package com.onpositive.dataminer.core;

import java.util.Set;

import com.onpositive.data.IPropertyConstants;
import com.onpositive.knowledge.model.IThing;
import com.onpositive.knowledge.model.value.audits.AbstractAuditResult;
import com.onpositive.knowledge.model.value.audits.AuditSourceContainer;
import com.onpositive.knowledge.model.value.audits.IValueAudit;
import com.onpositive.semantic.model.api.meta.DefaultMetaKeys;
import com.onpositive.semantic.model.api.property.IProperty;
import com.onpositive.units.ParsedSection;

public class IsInterestingThingAudit extends AuditSourceContainer  implements IValueAudit {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static final String ID = "is-interesting-thing-audit";

	@Override
	public void perform(IProperty prop, Iterable<Object> objects, AbstractAuditResult auditResult)
	{
		if( !(auditResult instanceof HasEnoughData) )
			return ;
		HasEnoughData dd = (HasEnoughData) auditResult ;
		
		for (Object o : objects) {
			IThing t = (IThing) o;
			Iterable<IProperty> properties = DefaultUniverse.getInstance()
					.getProperties(t);
			int count=0;
			for (IProperty p : properties) {
				if (DefaultMetaKeys.getValue(p, IPropertyConstants.CHAR_DEPRICATED_LABEL, Boolean.class,false)){
					continue;
				}
				if (p.getId().equals(IPropertyConstants.EXTERNAL_DEFAULT_PICTURE_PROPERTY_NAME)){
					continue;
				}
				if (p.getId().equals(IPropertyConstants.DOCUMENT_NAME_PROPERTY_METADATA_ID)){
					continue;
				}
				if (p.getId().equals(IPropertyConstants.PICTURE_LIST_PROPERTY_NAME)){
					continue;
				}
				String stringValue = DefaultMetaKeys.getStringValue(p, IPropertyConstants.CHAR_PARSER_ID_LABEL);
				if (stringValue!=null&& stringValue.equals(ParsedSection.ID)){
					continue;
				}
				Object value = p.getValue(t);
				if (value!=null){
					if (value instanceof Object[]){
						Object[] v=(Object[]) value;
						if (v.length==0){
							continue;
						}
					}
					count++;
				}
			}
			if (count<4){
				dd.addAsSuspicious(o);
				
			}
			else{
				dd.count++;
			}
			dd.totalCount++;
		}
	}

	@Override
	public AbstractAuditResult createAuditResult(IProperty prop) {
		return new HasEnoughData();
	}

	@Override
	public Set<String> getRequiredAudits() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getId() {
		return ID;
	}
}
